﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using BUS;
using DTO;

namespace BanSach
{
    public partial class frmNhanVien : Form
    {
        int typeSeach;
        public frmNhanVien()
        {
            InitializeComponent();
        }

        private void label9_Click(object sender, EventArgs e)
        {

        }

        private void groupBox5_Enter(object sender, EventArgs e)
        {

        }

        private void button2_Click(object sender, EventArgs e)
        {
            dataGridView1.DataSource = NhanVien_BUS.LoadNhanVien();
        }

        private void radioButton1_CheckedChanged(object sender, EventArgs e)
        {
            if (radioButton1.Checked)
            {
                typeSeach = 1;
            }
        }

        private void radioButton2_CheckedChanged(object sender, EventArgs e)
        {
            if (radioButton2.Checked)
            {
                typeSeach = 2;
            }
        }

        private void radioButton3_CheckedChanged(object sender, EventArgs e)
        {
            if (radioButton3.Checked)
            {
                typeSeach = 3;
            }
        }

        private void radioButton4_CheckedChanged(object sender, EventArgs e)
        {
            if (radioButton4.Checked)
            {
                typeSeach = 4;
            }
        }

        private void button1_Click(object sender, EventArgs e)
        {
            switch (typeSeach)
            {
                case 1:
                    {
                        dataGridView1.DataSource = NhanVien_BUS.TimMa(textBox1.Text);
                        break;
                    }
                case 2:
                    {
                        dataGridView1.DataSource = NhanVien_BUS.TimTenNV(textBox1.Text);
                        break;
                    }
                case 3:
                    {
                        dataGridView1.DataSource = NhanVien_BUS.TimQueQuanNV(textBox1.Text);
                        break;
                    }
                default:
                    {
                        dataGridView1.DataSource = NhanVien_BUS.TimChucVu(textBox1.Text);
                        break;
                    }
            }
        }

        private void button3_Click(object sender, EventArgs e)
        {
            dataGridView2.DataSource = NhanVien_BUS.LoadNhanVien();
        }

        private void button7_Click(object sender, EventArgs e)
        {
            string manv = textBox9.Text;
            string tennv = textBox4.Text;
            string quequan = textBox5.Text;
            string sdt = textBox6.Text;
            string gioitinh = textBox7.Text;
            string noio = textBox8.Text;
            string chucvu = textBox2.Text;
            NhanVien_DTO nv = new NhanVien_DTO(manv, tennv, quequan, sdt, gioitinh, noio, chucvu);
            NhanVien_BUS.ThemNhanVien(nv);
            dataGridView2.DataSource = NhanVien_BUS.LoadNhanVien();
        }

        private void button6_Click(object sender, EventArgs e)
        {
            string manv = textBox9.Text;
            string tennv = textBox4.Text;
            string quequan = textBox5.Text;
            string sdt = textBox6.Text;
            string gioitinh = textBox7.Text;
            string noio = textBox8.Text;
            string chucvu = textBox2.Text;
            NhanVien_DTO nv = new NhanVien_DTO(manv, tennv, quequan, sdt, gioitinh, noio, chucvu);
            NhanVien_BUS.SuaNhanVien(nv);
            dataGridView2.DataSource = NhanVien_BUS.LoadNhanVien();
        }

        private void button5_Click(object sender, EventArgs e)
        {
            NhanVien_BUS.XoaNhanVien(textBox3.Text);
            dataGridView2.DataSource = NhanVien_BUS.LoadNhanVien();
        }

        private void tabPage2_Click(object sender, EventArgs e)
        {

        }
    }
}
